package twitter;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

public class Analyse {
	public static void main(String[] args){
		TwitterServer tServer = new TwitterServer(null);
		Connection myConnection = tServer.getConnection();
	    Statement statement = null;
	    ResultSet rs = null;
	    
	    try {
			statement = myConnection.createStatement();
			rs = statement.executeQuery("SELECT id from user where name is not null order by rand() limit 500");
			int[] ids = new int[500];
			int i = 0;
			while(rs.next()){
				ids[i] = rs.getInt(1);
				i++;
			}
			for(int id:ids){
				int numFollowers = 0;
				int numFollowings = 0;
				int tweets = 0;
				ResultSet rs1 = statement.executeQuery("select followers from followers where id = "+ id);
				if(rs1.next()){
					String[] followers = rs1.getString(1).split(",");
					numFollowers = followers.length;
				}
				
				
				ResultSet rs2 = statement.executeQuery("select followers from followers where id = "+ id);
				if(rs2.next()){
					String[] followings = rs2.getString(1).split(",");
					numFollowings = followings.length;
				}
				
				ResultSet rs3 = statement.executeQuery("select count(id) from tweets where owner = "+ id);
				if(rs3.next()){
					tweets = rs3.getInt(1);
				}
				if(numFollowers >= 1)
					System.out.println(numFollowers+","+ tweets);
			}
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
